const { ccclass, property } = cc._decorator;

export enum IndicatorColorType {
    WARM,
    DANGE,
    SAFE,
}

@ccclass
export default class Indicator extends cc.Component {
    @property
    range: number = 0;

    @property(cc.Color)
    private _strokeColor: cc.Color = cc.Color.WHITE;
    @property(cc.Color)
    public get strokeColor(): cc.Color {
        return this._strokeColor;
    }
    public set strokeColor(value: cc.Color) {
        this._strokeColor = value;
        if (this._gh) {
            this._gh.strokeColor = value;
        }
    }

    @property(cc.Color)
    private _fillColor: cc.Color = cc.Color.WHITE;
    @property(cc.Color)
    public get fillColor(): cc.Color {
        return this._fillColor;
    }
    public set fillColor(value: cc.Color) {
        this._fillColor = value;
        if (this._gh) {
            this._gh.fillColor = value;
        }
    }

    private _gh: cc.Graphics = null;

    onLoad() {
        this._gh = this.node.addComponent(cc.Graphics);
        this._gh.lineWidth = 5;
        this._gh.strokeColor = this.strokeColor;
        this._gh.fillColor = this.fillColor;
    }

    protected update(dt: number): void {
        this._gh.clear();
        this._gh.circle(0, 0, this.range);
        this._gh.fill();
        this._gh.stroke();
    }

    setColorType(type: IndicatorColorType) {
        switch (type) {
            case IndicatorColorType.SAFE:
                this.strokeColor = cc.Color.GREEN;
                this.fillColor = cc.color(0, 255, 0, 75);
                break;
            case IndicatorColorType.WARM:
                this.strokeColor = cc.Color.YELLOW;
                this.fillColor = cc.color(255, 235, 4, 75);
                break;
            case IndicatorColorType.DANGE:
                this.strokeColor = cc.Color.RED;
                this.fillColor = cc.color(255, 0, 0, 75);
                break;
        }
    }
}